<?php
require_once("ClasseBanco.php");

/**
 * Classe transporte
 *
 * @author jorge
 * @version 1.0
 * 
 * CREATE TABLE "TRANSPORTE" 
(
  "TCNPJ"	 VARCHAR(18) NOT NULL,
  "TRAZAO"	 VARCHAR(60),
  "TIE"	 VARCHAR(14),
  "TENDERECO"	 VARCHAR(60),
  "TMUNICIPIO"	 VARCHAR(35),
  "TUF"	 VARCHAR(2),
CONSTRAINT "PK_TRANSPORTE" PRIMARY KEY ("TCNPJ")
);
 * Alt + Insert ==> Gerar os construtor e get set
 */
class transporte {

    public $_tcnpj;
    public $trazao;
    public $tie;
    public $tendereco;
    public $tmunicipio;
    public $tuf;

    function __construct($_tcnpj, $trazao, $tie, $tendereco, $tmunicipio, $tuf) {
        $this->_tcnpj = $_tcnpj;
        $this->trazao = $trazao;
        $this->tie = $tie;
        $this->tendereco = $tendereco;
        $this->tmunicipio = $tmunicipio;
        $this->tuf = $tuf;
    }

    public function get_tcnpj() {
        return $this->_tcnpj;
    }

    public function set_tcnpj($_tcnpj) {
        $this->_tcnpj = $_tcnpj;
    }

    public function getTrazao() {
        return $this->trazao;
    }

    public function setTrazao($trazao) {
        $this->trazao = $trazao;
    }

    public function getTie() {
        return $this->tie;
    }

    public function setTie($tie) {
        $this->tie = $tie;
    }

    public function getTendereco() {
        return $this->tendereco;
    }

    public function setTendereco($tendereco) {
        $this->tendereco = $tendereco;
    }

    public function getTmunicipio() {
        return $this->tmunicipio;
    }

    public function setTmunicipio($tmunicipio) {
        $this->tmunicipio = $tmunicipio;
    }

    public function getTuf() {
        return $this->tuf;
    }

    public function setTuf($tuf) {
        $this->tuf = $tuf;
    }

    
    public function montaTransporte($condicao) 
    {
        $ba = new bancoDados();
        $sql = $ba->montaSelectSQL($this) . $condicao;
        return $ba->executaQuery($sql);
    }

    public function montaTransporteConsulta($condicao) 
    {
        $ba = new bancoDados();
        $sql = $ba->montaSelectSQL($this) . $condicao;
        return $ba->executaQueryConsulta($sql);
    }

    public function incluirTransporte() 
    {
        $ba = new bancoDados();
        $sql = $ba->montaIncluirSQL($this);
        $ba->atualizaQuery($sql);
        return true;
    }

    public function alterarTransporte() 
    {
    	$ba = new bancoDados();
        $sql = $ba->montaAtualizarSQL($this);
	$ba->atualizaQuery($sql);
	return true;
    }

    public function excluirTransporte() 
    {
	$ba = new bancoDados();
        $sql = $ba->montaExcluirSQL($this);
	$ba->atualizaQuery($sql);
	return true;
    }

    public function XMLTransporte($cCondicao) {

        $rs = $this->montaTransporteConsulta($cCondicao);

        header("Content-type:application/xml;");
	$xml = "<?xml version='1.0' encoding='iso-8859-1'?>\r\n";

        global $xml;

	$xml .= "<transportes>";

        foreach ($rs as $row)
        {
            if ( $rs != '' )
            {
                    $xml .= "<transporte>";
                    $xml .=     "<tcnpj>"      . Trim($row['TCNPJ'])                  . "</tcnpj>";
                    $xml .=     "<trazao>"     . utf8_encode(Trim($row['TRAZAO']))    . "</trazao>";
                    $xml .=     "<tie>"        . Trim($row['TIE'])                    . "</tie>";
                    $xml .=     "<tendereco>"  . utf8_encode(Trim($row['TENDERECO'])) . "</tendereco>";
                    $xml .=     "<tmunicipio>" . utf8_encode(Trim($row['TMUNICIPIO'])). "</tmunicipio>";
                    $xml .=     "<tuf>"        . Trim($row['TUF'])                    . "</tuf>";
                    $xml .= "</transporte>";
            }
	}
	$xml .= '</transportes>';
	echo $xml;
        return;
    }
}
?>
